package com.abbas.myviewtest.activity;

import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.abbas.myviewtest.App;
import com.abbas.myviewtest.R;
import com.abbas.myviewtest.activity.adapter.ScoreListAdapter;
import com.abbas.myviewtest.activity.base.BaseActivity;
import com.abbas.myviewtest.entity.Record;

import org.xutils.ex.DbException;

import java.util.List;

public class ScoreRecordActivity extends BaseActivity {

    private ImageView imBack;
    private TextView tvTitle;
    private ListView lvScore;

    private List<Record> records;
    private ScoreListAdapter scoreListAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_score_record;
    }

    @Override
    protected void init() {
        imBack = (ImageView) findViewById(R.id.im_back);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        lvScore = (ListView) findViewById(R.id.lv_score);
        initData();
        initEvent();
    }

    private void initData() {
        try {
            records =  App.dbManager.findAll(Record.class);
            if (records != null && records.size() != 0){
                if (scoreListAdapter == null){
                    scoreListAdapter = new ScoreListAdapter(records,ScoreRecordActivity.this);
                }else {
                    scoreListAdapter.setRecords(records);
                }
                lvScore.setAdapter(scoreListAdapter);
            }
        } catch (DbException e) {
            e.printStackTrace();
        }
    }

    private void initEvent() {

    }
}